import {
	ChartViewActionType,
	IChartViewAbility,
	IParam,
} from '@/core/interface';
import { IChartViewController } from '@/core/interface/view/controller';
import { IChartViewControllerParams } from '@/core/interface/view/controller-params';
import { IChartViewStore } from '@/core/interface/view/store';
import {
	IChartAbility,
	ISearchFormAbility,
} from '@/core/interface/widgets/ability';
import { deepCopy } from '@/core/utils';
import { MDViewController } from './md-view-controller';

/**
 * 图表视图控制器
 *
 * @export
 * @class ChartViewController
 * @extends {ViewController}
 */
export class ChartViewController
	extends MDViewController<
		ChartViewActionType,
		IChartViewStore,
		IChartViewAbility
	>
	implements IChartViewController<IChartViewStore, IChartViewAbility>
{
	/**
	 * 处理视图初始化
	 *
	 * @protected
	 * @param {IChartViewControllerParams<ChartViewActionType, IChartViewAbility>} params
	 * @memberof ChartViewController
	 */
	protected processViewInit(
		params: IChartViewControllerParams<ChartViewActionType, IChartViewAbility>
	) {
		super.processViewInit(params);
	}

	/**
	 * 获取图表部件能力
	 *
	 * @protected
	 * @return {*}  {(IChartAbility | undefined)}
	 * @memberof ChartViewController
	 */
	protected getMainCtrlAbility(): IChartAbility | undefined {
		const chart = this.model.ctrls.find(
			(ctrl: IParam) => ctrl.controlType === 'CHART'
		);
		if (chart) {
			return this.getSubAbility<IChartAbility>(chart.name);
		}
		return undefined;
	}
}
